package com.windchime.blog.controller.lib.aly;

import com.windchime.blog.controller.lib.aly.service.OssService;
import com.windchime.blog.result.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/admin")
public class OssController {

    @Autowired
    private OssService ossService;

    /**
     * 上传用户头像
     * @param file 用户头像
     * @return url
     */
    @PostMapping("/upload/uploadUserAvatar")
    public R uploadUserAvatar(@RequestParam("file") MultipartFile file) {

        String url = ossService.uploadUserAvatar(file);

        return R.ok().data("url", url);
    }

    /**
     * 上传博客封面
     * @param file 博客封面
     * @return url
     */
    @PostMapping("/upload/uploadBlogCover")
    public R uploadBlogCover(@RequestParam("file") MultipartFile file) {

        String url = ossService.uploadBlogCover(file);

        return R.ok().data("url", url);
    }

    /**
     * 上传友链封面
     * @param file 友链封面
     * @return url
     */
    @PostMapping("/upload/uploadFriendCover")
    public R uploadFriendCover(@RequestParam("file") MultipartFile file) {

        String url = ossService.uploadFriendCover(file);

        return R.ok().data("url", url);
    }

    /**
     * 上传资源封面
     * @param file 友链封面
     * @return url
     */
    @PostMapping("/upload/uploadResourceCover")
    public R uploadResourceCover(@RequestParam("file") MultipartFile file) {

        String url = ossService.uploadResourceCover(file);

        return R.ok().data("url", url);
    }
}
